<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    const nums = [6,9,13,14,3];
    const newNums = nums.filter(function (n) {
        return n < 10;
    })
    console.log(nums);
    console.log(newNums);
    
    const newNums1 = nums.map(function (n) {
        return n * 2;
    });
    console.log(newNums1);
    
    // reduce的使用  
    // 0:preValue的初始值，之后每次preValue的值都为上次return的preValue + n的值
    let totalValue = nums.reduce(function (preValue, n) {
        return preValue + n;
    },0)
    console.log(totalValue);


    totalValue = nums.filter(function (n) {
        return n < 10
    }).map(function (n) {
        return n * 2
    }).reduce(function (preValue, n) {
        return preValue + n
    }, 0)
    console.log(totalValue)

    totalValue = nums.filter(n => n < 10).map(n => n * 2).reduce((preValue,n) => preValue + n, 0);
    console.log(totalValue)
</script>

</body>
</html>